package com.up.management.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.up.common.annotation.Log;
import com.up.common.core.controller.BaseController;
import com.up.common.core.domain.AjaxResult;
import com.up.common.enums.BusinessType;
import com.up.management.domain.entity.ItemRegion;
import com.up.management.domain.vo.ItemRegionVO;
import com.up.management.service.IItemRegionService;
import com.up.common.utils.poi.ExcelUtil;
import com.up.common.core.page.TableDataInfo;

/**
 * 项目地区Controller
 * 
 * @author cloud
 * @date 2025-01-15
 */
@RestController
@RequestMapping("/management/ItemRegion")
public class ItemRegionController extends BaseController
{
    @Autowired
    private IItemRegionService itemRegionService;

    /**
     * 查询项目地区列表
     */
    @PreAuthorize("@ss.hasPermi('management:ItemRegion:list')")
    @GetMapping("/list")
    public TableDataInfo list(ItemRegion itemRegion)
    {
        startPage();
        List<ItemRegionVO> list = itemRegionService.selectItemRegionVOList(itemRegion);
        return getDataTable(list);
    }

    /**
     * 导出项目地区列表
     */
    @PreAuthorize("@ss.hasPermi('management:ItemRegion:export')")
    @Log(title = "项目地区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ItemRegion itemRegion)
    {
        List<ItemRegion> list = itemRegionService.selectItemRegionList(itemRegion);
        ExcelUtil<ItemRegion> util = new ExcelUtil<ItemRegion>(ItemRegion.class);
        util.exportExcel(response, list, "项目地区数据");
    }

    /**
     * 获取项目地区详细信息
     */
    @PreAuthorize("@ss.hasPermi('management:ItemRegion:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(itemRegionService.selectItemRegionById(id));
    }

    /**
     * 新增项目地区
     */
    @PreAuthorize("@ss.hasPermi('management:ItemRegion:add')")
    @Log(title = "项目地区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ItemRegion itemRegion)
    {
        return toAjax(itemRegionService.insertItemRegion(itemRegion));
    }

    /**
     * 修改项目地区
     */
    @PreAuthorize("@ss.hasPermi('management:ItemRegion:edit')")
    @Log(title = "项目地区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ItemRegion itemRegion)
    {
        return toAjax(itemRegionService.updateItemRegion(itemRegion));
    }

    /**
     * 删除项目地区
     */
    @PreAuthorize("@ss.hasPermi('management:ItemRegion:remove')")
    @Log(title = "项目地区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(itemRegionService.deleteItemRegionByIds(ids));
    }
}
